#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vector>
#include <time.h>

#define MIN_DISTANCE 1
#define MAX_DISTANCE 100

using namespace std;
/**
 * Generate random netflow and save it to file netflow[number of edges].txt
 * @param argc
 * @param argv[1] Number of edges
 * @return 
 */
main(int argc, char** argv) {
    if(argc != 2){
        cout << "Usage\ngridgen numberOfEdges" << endl; 
        return -1;
    }

    /* initialize random seed: */
    srand (time(NULL));
  
    int edges = atoi(argv[1]);
    vector<vector<long> > distanceMatrix(edges);
    for(int i=0; i<edges; i++){
        distanceMatrix[i].resize(edges);
    }
   
    for(int i=0; i<edges; i++){
        distanceMatrix[i][i] = 0;
        for(int j=i+1; j<edges; j++){
             long d = rand() % MAX_DISTANCE + MIN_DISTANCE;
             distanceMatrix[i][j] = d;
             distanceMatrix[j][i] = d;
        }
    }
    
    string filePath;
    sprintf((char*)filePath.c_str(), "../netflow%d.txt", edges);

    ofstream myfile(filePath.c_str(),  ios::binary | ios::out | ios::trunc);
    if (myfile.is_open())
    {
        myfile << edges << endl;
        for(int i=0; i<edges; i++){
            for(int j=0; j<edges; j++){
                 myfile << distanceMatrix[i][j] << "\t";
            }
            myfile << endl;
        }
    }
    myfile.close();
    
    return 0;
}

